package GUIs;

import java.awt.ComponentOrientation;
import java.awt.Font;

import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.JTextArea;

import Cinema.CinemaSystem;

class MessageUI {

	static ImageIcon icon_error32 = new ImageIcon(ConnectionUI.class.getResource("/resources/error32.png"));
	static ImageIcon icon_ok32 = new ImageIcon(ConnectionUI.class.getResource("/resources/ok32.png"));
	static ImageIcon icon_service32 = new ImageIcon(ConnectionUI.class.getResource("/resources/external32.png"));

	/**
	 * Shows popUp window with error message.
	 * @param message - text to show.
	 */
	public static void showErrorMessage(String message){
		if (CinemaSystem.isTesting){
			return;
		}
		
		JTextArea text = new JTextArea(message);
		text.setFont(new Font("Arial", Font.PLAIN, 12));
		text.setBackground(null);
		JFrame frame = new JFrame();
		frame.setComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT);
		JOptionPane.showMessageDialog(frame, text, "Cinema", JOptionPane.ERROR_MESSAGE, icon_error32);
	}

	/**
	 * Shows popUp window with info message.
	 * @param message - text to show.
	 */
	public static void showInfoMessage(String message){
		if (CinemaSystem.isTesting){
			return;
		}
		
		JTextArea text = new JTextArea(message);
		text.setFont(new Font("Arial", Font.PLAIN, 12));
		text.setBackground(null);
		JFrame frame = new JFrame();
		frame.setComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT);
		JOptionPane.showMessageDialog(frame, text, "Cinema", JOptionPane.INFORMATION_MESSAGE, icon_ok32);
	}

	/**
	 * Shows popUp window, indicating use of external service.
	 * @param service - name of external service.
	 * @param message - text to show.
	 */
	public static void showExternalServiceMessage(String service, String message){
		if (CinemaSystem.isTesting){
			return;
		}
		
		JTextArea text = new JTextArea(message);
		text.setFont(new Font("Arial", Font.PLAIN, 12));
		text.setBackground(null);
		JFrame frame = new JFrame();
		frame.setComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT);
		JOptionPane.showMessageDialog(frame, text, service, JOptionPane.INFORMATION_MESSAGE, icon_service32);
	}

}
